package com.qf.test.controller;

import com.qf.test.entity.User;
import com.qf.test.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public String login(String username, String pwd, Model model, HttpSession session){
        User user = userService.login(username, pwd);
        if (user == null){
            model.addAttribute("msg","用户名或密码错误");
            return "/index";
        }else {
            session.setAttribute("currentUser", user);
            return "redirect:/list";
        }
    }

    @RequestMapping("/list")
     public String list(Model model){
       List<User> list = userService.findAll();
       model.addAttribute("list", list);
       return "/info/list";
     }
}
